<!-- head -->
{include file='public/head' /}
<!-- head -->

<!-- left -->
{include file='public/left' /}
<!-- left -->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            管理后台
            <small>1.0.0</small>
        </h1>
        <ol class="breadcrumb">
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box box-default">
                    <div class="box-header with-border">
                        <h3 class="box-title">编辑媒体报道</h3>
                    </div>
                    <form class="form-horizontal" id="form"  action="{:url('admin/meiti/postsave','','')}"  >
                        {if condition="isset($id)"}     <input type="hidden" id="id" value="{$id}"> {/if}
                        <div class="box-body">
                            <div class="form-group">
                                <label for="webname" class="col-sm-2 control-label">网站名称</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="webname" name="webname" placeholder="网站名称" {present name="$row"} value="{$row.webname }" {/present} >
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="title" class="col-sm-2 control-label">标题</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="title" name="title" placeholder="标题" {present name="$row"} value="{$row.title}" {/present}>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="img" class="col-sm-2 control-label">媒体logo</label>
                                <div class="col-sm-10">
                                    <input type="file" class="form-control" {present name="$row"} value="{$row.img}" {/present} id="img" name="img">
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="title" class="col-sm-2 control-label">描述</label>
                                <div class="col-sm-10">
                                    <textarea name="content"  id="content" cols="100" rows="10">{present name="$row"} {$row.content} {/present}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="url" class="col-sm-2 control-label">链接地址</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id="url" name="url" placeholder="链接地址" {present name="$row"} value="{$row.url}" {/present}>
                                    <span class="help-block" style="color:#f00;"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="text-align:right;">
                            <button type="button" class="btn btn-sm btn-default" id="resetForm">清空</button>&nbsp;
                            <button type="button" class="btn btn-sm btn-primary" id="saveForm">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<line href="__STATIC__/bootstrap-fileinput/css/fileinput.css" type="text/css" rel="stylesheet" />
<script src="__STATIC__/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
<script src="__STATIC__/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script type="text/javascript">

    var imgName = '';

    $("#img").fileinput({
        language : 'zh',
        showRemove: false,
        showUpload: true,
        showClose: false,
        showPreview: false,
        allowedFileTypes: ['image'],
        allowedFileExtensions : ['jpg', 'jpeg', 'png', 'gif'],
        uploadUrl: '{:url("admin/public/uploadimg","","")}',
        uploadExtraData: {
            'folder': 'pic',
        },
    });

    $("#img").on("fileuploaded", function (event, data, previewId, index) {
        var result = data.response;
        if (result.status == 1) {
            imgName = result.data;
        } else {
            showAlert('提示', result.info, null);
        }
    });
</script>
<script type="text/javascript">

    $(function(){
        $('#resetForm').click(function(){
            $('#name').val('');
        });

        $('#saveForm').click(function(){
            var webname = $.trim($('#webname').val());
            if (webname == '') {
                $('#webname').parents('.form-group').addClass('has-error');
                $('#webname').parent().find('.help-block').html('请输入网站名称');
                return false;
            }

            var title = $.trim($('#title').val());
            if (title == '') {
                $('#title').parents('.form-group').addClass('has-error');
                $('#title').parent().find('.help-block').html('请输入标题');
                return false;
            }

            var url = $.trim($('#url').val());
            if (url == '') {
                $('#url').parents('.form-group').addClass('has-error');
                $('#url').parent().find('.help-block').html('请输入链接地址');
                return false;
            }

            $.ajax({
                url: $('#form').attr('action'),
                type: 'POST',
                data: {
                    'id': $('#id').val(),
                    'webname': webname,
                    'title': title,
                    'url': url,
                    'img':imgName,
                    'content':$("#content").val()
                },
                dataType: 'JSON',
                success: function(data) {
                    if (data.status == 1) {
                        window.location.href = "{:url('admin/meiti/index','','')}";
                    } else {
                        showAlert('提示', data.info, null);
                    }
                }
            });
        });

        $('#artcate_id').focus(function(){
            if ($('#artcate_id').parents('.form-group').hasClass('has-error')) {
                $('#artcate_id').parents('.form-group').removeClass('has-error');
                $('#artcate_id').parent().find('.help-block').html('');
            }
        });

        $('#title').focus(function(){
            if ($('#title').parents('.form-group').hasClass('has-error')) {
                $('#title').parents('.form-group').removeClass('has-error');
                $('#title').parent().find('.help-block').html('');
            }
        });

        $('#source').focus(function(){
            if ($('#source').parents('.form-group').hasClass('has-error')) {
                $('#source').parents('.form-group').removeClass('has-error');
                $('#source').parent().find('.help-block').html('');
            }
        });

        $('#img').focus(function(){
            if ($('#img').parents('.form-group').hasClass('has-error')) {
                $('#img').parents('.form-group').removeClass('has-error');
                $('#img').parents('.form-group').find('.help-block').html('');
            }
        });

        $('#content').focus(function(){
            if ($('#content').parents('.form-group').hasClass('has-error')) {
                $('#content').parents('.form-group').removeClass('has-error');
                $('#content').parent().find('.help-block').html('');
            }
        });

    });

</script>

<!-- right -->
{include file='public/right' /}
<!-- right -->

<!-- foot -->
{include file='public/foot' /}
<!-- foot -->
